package com.huosu.commons.enums;

import com.google.common.collect.Lists;
import lombok.Getter;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author zhangjian
 * @since 2019-12-10
 */
@Getter
public enum DataManipulationEnum {

    /**
     * 添加
     */
    INSERT(1,"insert"),

    /**
     * 修改
     */
    UPDATE(2,"update"),


    /**
     *  删除
     */
    DELETE(3,"delete"),

    /**
     *  所有（覆盖）
     */
    ALL(4,"all");


    private Integer code;

    private String value;


    DataManipulationEnum(Integer code, String value) {
        this.code = code;
        this.value = value;
    }

    public static List toList() {
        List list = Lists.newArrayList();
        for (DataManipulationEnum stateEnum : DataManipulationEnum.values()) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("code", stateEnum.getCode());
            map.put("value", stateEnum.getValue());
            list.add(map);
        }
        return list;
    }


    /**
     * 根据Key得到枚举的Value
     * Lambda表达式，比较判断（JDK 1.8）
     *
     * @param key
     * @return
     */
    public static DataManipulationEnum getEnumType(Integer key) {
        return Arrays.asList(DataManipulationEnum.values()).stream()
                .filter(e -> e.getCode().equals(key))
                .findFirst().orElse(null);
    }
}
